//
//  BangdingViewController.m
//  SelfDriving
//
//  Created by apple on 16/9/18.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "BangdingViewController.h"
#import "BusinessService+User.h"

@interface BangdingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneField;
@property (weak, nonatomic) IBOutlet UITextField *codeField;
@end

@implementation BangdingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)getCodeAction:(UIButton *)sender {
    if([_phoneField.text trim].length == 0 ){
        [SVProgressHUD showErrorWithStatus:@"请输入手机号"];
        return;
    }
    NSMutableDictionary *dic= [[NSMutableDictionary alloc]init];
    [dic setObject:[_phoneField.text trim] forKey:@"phone"];
    [dic setObject:@"4" forKey:@"type"];
    [[BusinessService shareInstance]getCode:dic success:^(id result) {
        [SVProgressHUD showSuccessWithStatus:@"获取验证码成功"];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
- (IBAction)submitAction:(UIButton *)sender {
    if([_phoneField.text trim].length == 0 ){
        [SVProgressHUD showErrorWithStatus:@"请输入手机号"];
        return;
    }
    if([_codeField.text trim].length == 0 ){
        [SVProgressHUD showErrorWithStatus:@"请输入验证码"];
        return;
    }
    NSMutableDictionary *dic= [[NSMutableDictionary alloc]init];
    [dic setObject:[_phoneField.text trim] forKey:@"phone"];
    [dic setObject:[ValidateHelper getID] forKey:@"deviceid"];
    [dic setObject:_codeField.text forKey:@"code"];
    [[BusinessService shareInstance]bindSafePhone:dic success:^(id result) {
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
